﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace QXBook.Handlers.AjaxHandlers
{
    public abstract class AjaxHandler : IHttpHandler
    {
        /// <summary>
        /// You will need to configure this handler in the web.config file of your 
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        public virtual string ContengType
        {
            get { return "text/html"; }
        }

        /// <summary>
        /// 输出数据，请继承
        /// </summary>
        /// <returns></returns>
        public abstract string GetBusinessData(HttpContext context);

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentEncoding = Encoding.UTF8;
            context.Response.ContentType = ContengType;

            AjaxMappingAttribute.Bind(this, context.Request.Params);

            context.Response.Output.Write(GetBusinessData(context));
            context.Response.End();
        }

        #endregion
    }
}
